<template>
	<Row :gutter="16">
		<ICol span="2" offset="12">
			<Select placeholder="关注" v-model="search.subscribe" @on-change="filter" clearable>
				<Option v-for="(subscribe,index) in subscribeArr" :key="index" :value="subscribe.value">{{subscribe.label}}</Option>
			</Select>
		</ICol>
		<ICol span="4" >
			<Input placeholder="请输入openid、昵称、备注 搜索" v-model="search.name" clearable></Input>
		</ICol>
		<ICol span="2">
			<Button type="primary" @click="filter">搜索</Button>
		</ICol>
        <ICol span="2">
            <Button v-if="$store.getters.per.wechat_manager_user_update" type="primary" @click="contactWechat" :disabled="sync.disabled">同步微信</Button>
        </ICol>
	</Row>
</template>
<script>
	import {Row,Col,Button,Input,Select,Option} from 'iview';

	export default{
		props:{
            searchCallBack:{
                type:Function
            }
        },
		components:{
			Row,
            'ICol':Col,
            Button,
            Input,
            Select,
            Option,
        },
        data(){
        	return {
                subscribeArr : [
                	{value: -1, label : '全部'},
                	{value: 0, label : '否'},
                	{value: 1, label : '是'},
                ],
                search:{
                	subscribe : '',
                    name : '',
                },
                sync:{
                    nextOpenid:'',
                    disabled : false,
                },
        	}
        },
        methods :{
            filter(){
                this.searchCallBack(this.search);
            },
            //同步微信用户
            syncWechat(){
                this.sync.disabled = true;
                this.Axios.Wechat.Manager.User.SyncWechatUser(this.sync)
                    .then(res =>{
                        if(!res){
                            this.sync.disabled = false;
                            return false;
                        }
                        var data = res.data;
                        if(data['next_openid'] &&  data['next_openid']!=''){
                            this.sync.nextOpenid = data['next_openid'];
                            var _this = this;
                            setTimeout(function(){
                                _this.syncWechat();
                            },2000);
                        }else{
                            this.sync.disabled = false;
                            this.filter(); 
                        }
                    })
            },
            contactWechat(){
                this.syncWechat();
            },
        },
	}
</script>